# -*- encoding: utf-8 -*-
"""
PyCharm div
2022年09月10日
by littlefean
"""
from typing import *
from animation import Ani
from tools import *


class Div:
    def __init__(self, size=(50, 50), backgroundColor=(20, 20, 20)):
        self.width, self.height = size
        self.marginLeft, self.marginTop = map(lambda x: -x // 2, size)
        self.backgroundColor = backgroundColor

        self.innerHtml = []  # 自己div里是不是会套别的东西
        self.borderRadius = 0
        self.outlineWidth = 0
        self.borderWidth = 0

        self.left: float = .5
        self.top: float = .5
        self.position = "absolute"

        # 动画时间有关属性
        self.animationDelay = 0
        # 总动画持续时间
        self.animationDuration = 0
        self.animationName = f"a{id(self)}"
        self.animationFillMode = "forwards"
        self.aniList: List[Tuple[dict, int]] = []  # 动画队列
        ...

    def __str__(self):
        ...

    def bodyStr(self):
        return f"<div class='d{id(self)}'></div>"

    def cssStr(self):
        return f"""
        .d{id(self)} {{
        {"".join([cssPairToStr(k, v) for k, v in self.__dict__.items()])}
        }}
        """

    def addAni(self, cssName: str, cssValue: Any, dur):
        """
        给当前div增加一段动画
        :return:
        """
        self.animationDuration += dur
        if not self.aniList:
            self.aniList.append(({cssName: cssValue}, dur))
        else:
            topDic = self.aniList[-1][0]
            self.aniList.append((topDic | {cssName: cssValue}, dur))
        ...

    def animationStr(self):
        beforeTime = 0
        curStr = f"0%{{ {''.join([cssPairToStr(k, v) for k, v in self.__dict__.items()])} }}"
        for cssDic, dur in self.aniList:
            beforeTime += dur
            r = f"{(beforeTime / self.animationDuration) * 100}%"
            dicStr = "".join(cssPairToStr(k, v) for k, v in cssDic.items())
            curStr += f"{r} {{ {dicStr} }}"
            ...
        return f"""
        @keyframes {self.animationName} {{
            {curStr}
        }}"""

    def test(self):
        for k, v in self.__dict__.items():
            print(k, v)


def main():
    # a = {"A": 15, "B": 2}
    # b = {"A": 20}
    # c = a | b | {"A": 201}
    # print(c)
    # c["A"] = 333
    size = (100, 200)
    a, b = map(lambda x: -x // 2, size)
    print(a, b)
    return None


if __name__ == "__main__":
    main()
